#
# Copyright 1999-2000,2004 The Apache Software Foundation.
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#      http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
#
# $Id: Makefile.in 176366 2005-04-05 09:21:57Z gareth $
#

###################################################################
#                    IMPORTANT NOTE                               #
###################################################################
# Before you try to run the Makefile, make sure you have two      #
# environment variables set.                                      #
#                                                                 #
# export XERCESCROOT=<the directory where you installed XERCES-C> #
#     export ICUROOT=<the directory where you installed ICU>      #
#                                                                 #
###################################################################
#all these setting come from the arguments passed in to runConfigure.
PLATFORM = @platform@
CC  = @cc@
CXX = @cxx@
CXXVER = @cxxver@
PREFIX = @prefix@
MESSAGELOADER=@messageloader@
TRANSCODER=@transcoder@

GCC = @GCC@
GXX = @GXX@

#MACROS defining commands
MKDIR=mkdir
CP=cp
CD=cd
RM=rm
CHMODE=chmod

include ../../version.incl
include Makefile.incl

UTIL_DIR = util
SAX_DIR = sax
SAX2_DIR = sax2
INTERNAL_DIR = internal
FRAMEWORK_DIR = framework
DOM_DIR = dom
PARSERS_DIR = parsers
VALIDATORS_DIR = validators

PRODUCTNAME=xerces
PRODUCTVERSION=${VER}
BINTARGETNAME=${PRODUCTNAME}-c-${PLATFORM}-${CXX}-${PRODUCTVERSION}
BINTARGETDIR=${HOME}/${BINTARGETNAME}

all:: lib

compile:: Prepare Util Sax Internal Framework Parsers Sax2 Dom Validators

ifeq (${PLATFORM},CYGWIN)
lib:: ${FQ_SO_NAME}
else
lib:: ${FQ_REAL_NAME}
endif

Prepare::
	@echo Preparing the directory structure for a build ...
	$Q${MKDIR} -p ${XML_OBJ_DIR}
	$Q${MKDIR} -p ${XML_OBJ_DEPDOM_DIR}
	$Q${MKDIR} -p ${XML_LIB_DIR}
	$Q${MAKE} -s -C $(UTIL_DIR) includes
	$Q${MAKE} -s -C $(SAX_DIR) includes
	$Q${MAKE} -s -C $(SAX2_DIR) includes
	$Q${MAKE} -s -C $(INTERNAL_DIR) includes
	$Q${MAKE} -s -C $(FRAMEWORK_DIR) includes
	$Q${MAKE} -s -C $(PARSERS_DIR) includes
	$Q${MAKE} -s -C $(VALIDATORS_DIR) includes
	$Q${MAKE} -s -C $(DOM_DIR) includes

Util::
	@echo Building "util"
	$Q${MAKE} -s -C $(UTIL_DIR) $(MAKE_FLAGS)

Sax::
	@echo Building "sax"
	$Q${MAKE} -s -C $(SAX_DIR) $(MAKE_FLAGS)


Internal::
	@echo Building "internal"
	$Q${MAKE} -s -C $(INTERNAL_DIR) $(MAKE_FLAGS)

Framework::
	@echo Building "framework"
	$Q${MAKE} -s -C $(FRAMEWORK_DIR) $(MAKE_FLAGS)

Parsers::
	@echo Building "parsers"
	$Q${MAKE} -s -C $(PARSERS_DIR) $(MAKE_FLAGS)

Sax2::
	@echo Building "sax2"
	$Q${MAKE} -s -C $(SAX2_DIR) $(MAKE_FLAGS)

Dom::
	@echo Building "dom"
	$Q${MAKE} -s -C $(DOM_DIR) $(MAKE_FLAGS)

Validators::
	@echo Building "validators"
	$Q${MAKE} -s -C $(VALIDATORS_DIR) $(MAKE_FLAGS)

ifeq (${PLATFORM},CYGWIN)
${FQ_SO_NAME}:: compile
	@echo Building ${FQ_SO_NAME}
	$Q${MAKE} -s -C $(XML_OBJ) -k $(MAKE_FLAGS)
else
${FQ_REAL_NAME}:: compile
	@echo toplevel Building ${FQ_REAL_NAME}
	$Q${MAKE} -C $(XML_OBJ) -k $(MAKE_FLAGS)
endif

install::
	${MAKE} -C $(UTIL_DIR) $@
	${MAKE} -C $(SAX_DIR) $@
	${MAKE} -C $(SAX2_DIR) $@
	${MAKE} -C $(INTERNAL_DIR) $@
	${MAKE} -C $(FRAMEWORK_DIR) $@
	${MAKE} -C $(PARSERS_DIR) $@
	${MAKE} -C $(DOM_DIR) $@
	${MAKE} -C $(VALIDATORS_DIR) $@
	${MAKE} -C $(XML_OBJ) $@
	
clean::
	${MAKE} -C $(UTIL_DIR) $@
	${MAKE} -C $(SAX_DIR) $@
	${MAKE} -C $(SAX2_DIR) $@
	${MAKE} -C $(INTERNAL_DIR) $@
	${MAKE} -C $(FRAMEWORK_DIR) $@
	${MAKE} -C $(PARSERS_DIR) $@
	${MAKE} -C $(DOM_DIR) $@
	${MAKE} -C $(VALIDATORS_DIR) $@
	${MAKE} -C $(XML_OBJ) $@
	
distclean::
	${MAKE} -C $(UTIL_DIR) $@
	${MAKE} -C $(SAX_DIR) $@
	${MAKE} -C $(SAX2_DIR) $@
	${MAKE} -C $(INTERNAL_DIR) $@
	${MAKE} -C $(FRAMEWORK_DIR) $@
	${MAKE} -C $(PARSERS_DIR) $@
	${MAKE} -C $(DOM_DIR) $@
	${MAKE} -C $(VALIDATORS_DIR) $@
	${MAKE} -C $(XML_OBJ) $@
	rm -f Makefile config.cache config.log config.status
	find . -name Makefile -print -exec rm -f {} \;
	rm -Rf ${XML_OBJ_DIR} ${XML_OBJ_DEPDOM_DIR} ${XML_LIB_DIR} ../../include
	rm -f *~ core

#docs::

samples::
	${MAKE} -C ../../samples

copy:: lib samples
	@echo Make the target directory and its main subdirectories
	-${MKDIR} ${BINTARGETDIR}
	-${MKDIR} ${BINTARGETDIR}/bin
	-${MKDIR} ${BINTARGETDIR}/etc
	-${MKDIR} ${BINTARGETDIR}/lib
ifeq (${MESSAGELOADER},ICU)
	-${MKDIR} ${BINTARGETDIR}/msg
endif
ifeq (${MESSAGELOADER},ICONV)
	-${MKDIR} ${BINTARGETDIR}/msg
endif
	-${MKDIR} ${BINTARGETDIR}/include
	-${MKDIR} ${BINTARGETDIR}/samples
	-${MKDIR} ${BINTARGETDIR}/doc
	-${MKDIR} ${BINTARGETDIR}/doc/html

	@echo Populate the include output directory
	@echo Copying headers files ...
	-${CP} -Rf ${XERCESCROOT}/include/* ${BINTARGETDIR}/include
	-${RM} -rf ${BINTARGETDIR}/include/xercesc/dom/impl
ifeq (${TRANSCODER},ICU)
	-${CP} -Rf ${ICUROOT}/include/* ${BINTARGETDIR}/include
else
   ifeq (${MESSAGELOADER},ICU)
	-${CP} -Rf ${ICUROOT}/include/* ${BINTARGETDIR}/include
   endif
endif

	@echo Populate the binary output directory
	@echo Copying binary outputs ...
	-${CP} -Rf ${XERCESCROOT}/bin/* ${BINTARGETDIR}/bin
	-${CP} -Rf ${XERCESCROOT}/src/xercesc/config.status ${BINTARGETDIR}/etc
	-${CP} -Rf ${XERCESCROOT}/bin/obj/*.map ${BINTARGETDIR}/etc
	-${CP} -Rf ${XERCESCROOT}/lib/${REAL_NAME} ${BINTARGETDIR}/lib
	-${CD} ${BINTARGETDIR}/lib; ln -s ${REAL_NAME} ${SO_NAME}; ln -s ${REAL_NAME} ${LINK_NAME}
ifeq (${TRANSCODER},ICU)
	-${CP} -Rf ${ICUROOT}/lib/libicudata32.0.so ${BINTARGETDIR}/lib
	-${CP} -Rf ${ICUROOT}/lib/libicudata.so.32.0 ${BINTARGETDIR}/lib
	-${CP} -Rf ${ICUROOT}/lib/libicudata.sl.32.0 ${BINTARGETDIR}/lib
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicudata32.0.so' -exec ln -s {} libicudata.so \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicudata32.0.so' -exec ln -s {} libicudata32.so \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicudata.so.32.0' -exec ln -s {} libicudata.so \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicudata.so.32.0' -exec ln -s {} libicudata.so.32 \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicudata.sl.32.0' -exec ln -s {} libicudata.sl \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicudata.sl.32.0' -exec ln -s {} libicudata.sl.32 \;
	-${CP} -Rf ${ICUROOT}/lib/libicuuc32.0.so ${BINTARGETDIR}/lib
	-${CP} -Rf ${ICUROOT}/lib/libicuuc.so.32.0 ${BINTARGETDIR}/lib
	-${CP} -Rf ${ICUROOT}/lib/libicuuc.sl.32.0 ${BINTARGETDIR}/lib
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicuuc32.0.so' -exec ln -s {} libicuuc.so \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicuuc32.0.so' -exec ln -s {} libicuuc32.so \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicuuc.so.32.0' -exec ln -s {} libicuuc.so \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicuuc.so.32.0' -exec ln -s {} libicuuc.so.32 \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicuuc.sl.32.0' -exec ln -s {} libicuuc.sl \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicuuc.sl.32.0' -exec ln -s {} libicuuc.sl.32 \;
else
   ifeq (${MESSAGELOADER},ICU)
	-${CP} -Rf ${ICUROOT}/lib/libicudata32.0.so ${BINTARGETDIR}/lib
	-${CP} -Rf ${ICUROOT}/lib/libicudata.so.32.0 ${BINTARGETDIR}/lib
	-${CP} -Rf ${ICUROOT}/lib/libicudata.sl.32.0 ${BINTARGETDIR}/lib
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicudata32.0.so' -exec ln -s {} libicudata.so \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicudata32.0.so' -exec ln -s {} libicudata32.so \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicudata.so.32.0' -exec ln -s {} libicudata.so \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicudata.so.32.0' -exec ln -s {} libicudata.so.32 \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicudata.sl.32.0' -exec ln -s {} libicudata.sl \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicudata.sl.32.0' -exec ln -s {} libicudata.sl.32 \;
	-${CP} -Rf ${ICUROOT}/lib/libicuuc32.0.so ${BINTARGETDIR}/lib
	-${CP} -Rf ${ICUROOT}/lib/libicuuc.so.32.0 ${BINTARGETDIR}/lib
	-${CP} -Rf ${ICUROOT}/lib/libicuuc.sl.32.0 ${BINTARGETDIR}/lib
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicuuc32.0.so' -exec ln -s {} libicuuc.so \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicuuc32.0.so' -exec ln -s {} libicuuc32.so \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicuuc.so.32.0' -exec ln -s {} libicuuc.so \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicuuc.so.32.0' -exec ln -s {} libicuuc.so.32 \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicuuc.sl.32.0' -exec ln -s {} libicuuc.sl \;
	-${CD} ${BINTARGETDIR}/lib; find . -name 'libicuuc.sl.32.0' -exec ln -s {} libicuuc.sl.32 \;
   endif
endif
ifeq (${MESSAGELOADER},ICU)
	-${CP} -f ${XERCESCROOT}/msg/*.res ${BINTARGETDIR}/msg
endif
ifeq (${MESSAGELOADER},ICONV)
	-${CP} -f ${XERCESCROOT}/msg/*.cat ${BINTARGETDIR}/msg
endif
	-${RM} -rf ${BINTARGETDIR}/bin/obj

	@echo Populate the samples directory
	@echo Copying sample files ...
	-${CP} -Rf ${XERCESCROOT}/samples/* 	${BINTARGETDIR}/samples
	-${RM2} `find ${BINTARGETDIR}/samples -name Makefile`

	@echo Populate the docs directory
	@echo Copying documentation ..
	-${CP} -f ${XERCESCROOT}/doc/index.html ${BINTARGETDIR}/doc
	-${CP} -Rf ${XERCESCROOT}/doc/html/* ${BINTARGETDIR}/doc/html
	-${CP} -f ${XERCESCROOT}/*.html ${BINTARGETDIR}
	-${CP} -f ${XERCESCROOT}/*.txt ${BINTARGETDIR}
	-${CP} -f ${XERCESCROOT}/version.incl ${BINTARGETDIR}

	@echo Change the directory permissions
	-${CHMODE} 644 `find ${BINTARGETDIR} -type f`
	-${CHMODE} 755 ${BINTARGETDIR}/bin/* ${BINTARGETDIR}/lib/*
	-${CHMODE} +x ${BINTARGETDIR}/samples/runConfigure ${BINTARGETDIR}/samples/configure ${BINTARGETDIR}/samples/install-sh
	-${CHMODE} +x ${BINTARGETDIR}/samples/config.sub ${BINTARGETDIR}/samples/config.guess ${BINTARGETDIR}/samples/config.status
	-${CHMODE} 755 `find ${BINTARGETDIR} -type d`

tarball:: copy
	@echo Now package it all up using tar
	@echo TARing up all files ...
	cd ${BINTARGETDIR}/..; tar -cvf ${BINTARGETDIR}.tar ${BINTARGETNAME}/
	@echo Finally compress the files
	@echo Compressing ${BINTARGETDIR}.tar ...
	gzip ${BINTARGETDIR}.tar

zip:: copy
	${CD} ${BINTARGETDIR}/..
	@echo ZIPping up all files ...
	zip -r ${BINTARGETDIR}.zip ${BINTARGETDIR}


package_bin:: zip tarball

